<?php
/**
 * Created by PhpStorm.
 * User: Nicof
 * Date: 2016/1/21
 * Time: 16:48
 */

namespace Admin\Controller;
use User\Api\UserApi as UserApi;


class PurchaseController extends AdminController{
    public function confirmpurchase(){
        $map['status'] = 3;
        $res = M('Purchase_list')->where($map)->order('createdAt')->select();
        $this->assign("_list",$res);
        $this->display();
    }
    public function purchaseList(){
        $list = M('Purchase_list')->where(array('status'=>4))->select();
        $list = int_to_string($list);
        $this->assign('_list',$list);
        $this->display('list');
    }
    public function details($id = null) {
        $map['id'] = $id;
        $list = M('Purchaselist')->where($map)->select();
        //int_to_string_order($orderlist);
        $purchase = $list[0];

        $this->purchase = $purchase;

        $this->display();
    }
    public function prodetail(){
        $map['batch'] = I('batch');
        $goods=M('purchase')->where($map)->select();
        $this->assign('_list',$goods);
        $this->display();
    }
    public function proaccept(){
        $map['batch'] = I('batch');
        $data['status'] = 4;
        $re=M('purchase_list')->where($map)->save($data);
        if($re){
            $this->success('确认成功',U('confirmpurchase'));
        }else{
            $this->error('确认失败',U('confirmpurchase'));
        }
    }
    public function history(){
        $list = M('Purchase_list')->order("createdAt desc")->select();
        $this->assign("_list",$list);
        $this->display();
    }
    public function purchaselistdetail(){
        $map['batch'] = I('batch');
        $map['status'] = array('gt',1);
        $list = M('Purchase')->where($map)->select();
        $this->assign('_list',$list);
        $this->display();

    }
    public function purchaseprodetail(){
        $map['batch'] = I('batch');
        $map['pid'] = I('pid');
        $pro = M('Purchase')->where($map)->find();
        $this->assign('pro',$pro);
        $this->display();
    }
}